/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package by.scsbsu.commands;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import by.scsbsu.file.tools.FileUploader;
import by.scsbsu.resources.managers.CookiesManager;
import by.scsbsu.resources.managers.PageLinksManager;

public class LogoutCommand implements Command {

    @Override
    public String execute(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {

    	FileUploader fU  = new FileUploader(request);
    	fU.uploadFile();
        String page = null;
        Cookie[] cookies = request.getCookies();
        for(Cookie cookie: cookies) {
        	if(CookiesManager.C_K_USER.equalsIgnoreCase(cookie.getName()) ||
        	   CookiesManager.C_K_PASS.equalsIgnoreCase(cookie.getName()) ||
        	   CookiesManager.C_K_SAVE.equalsIgnoreCase(cookie.getName())) 
        	{
        		cookie.setValue(null);
        		response.addCookie(cookie);
        	}
        }
        page = PageLinksManager.getProperty(PageLinksManager.LOGIN_PAGE_PATH);
        return page;
    }
}
